// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var css_detail_info = require("../financing/financingDetailInfo.css");
	var css_categorys = require("../main/financingDetailEvidentiaryCategorys1.css");
	var js_detail_info = require("./financingDetailInfo.js");
	var tools = require("tools");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var financeId;
	var financeAuditId;
	var fileName;
	var init = function(page) {
		financeId = page.params.financeId;
		financeAuditId = page.params.financeAuditId;
		initEvent();
		js_detail_info.init(page);
		$(".d2").css("background", "url(../../../res/png/tab_bg3.png) no-repeat bottom");
		showEvidentiaryCategorys();
		router.init();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		//点击首页
		$(".platform_main").unbind("click").click(function() {
			top.location.href = "../main/platform_main.html";
		});
		//待审批列表
		$(".financeApproveList").unbind("click").click(function() {
			router.route("main/main_finance.html?left=0&financeState=1", true);
		});

		//点击证明材料
		$(".evidentiaryCategorys1").on("click", function() {
			router.route("main/financingDetailEvidentiaryCategorys1.html?financeId=" + financeId + "&financeAuditId=" + financeAuditId);
		});

		//点击融资申请基本信息
		$(".financeDetailInfo1").on("click", function() {
			router.route("main/financingDetailInfo1.html?financeId=" + financeId + "&financeAuditId=" + financeAuditId);
		});

		//点击融资评审
		$(".financingDetailDynamic1").on("click", function() {
			router.route("main/financeApproveDetail.html?financeAuditId=" + financeAuditId);
		});
	};

	var showEvidentiaryCategorys = function() {
		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",
			oData: {

				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (data.datas[0].evidentiaryCategorys.length == 0) {
						$("#evidentiaryCategorysBody").html("暂无数据");
					} else {
						var tpl = $("#evidentiaryCategorysTpl").html();
						var html = juicer(tpl, data);
						$("#evidentiaryCategorysBody").html(html);
						var materialItems = $(".materialItem");
						for (var j = 0; j < materialItems.length; j++) {
							$(materialItems[j]).find(".d11 span").html(tools.inquireFile($(materialItems[j]).find(".d11").attr("materialFileuuid")));
							for (var k = materialItems.length - j + 1; k > 1; k--) {
								if ($(materialItems[k]).attr("templateId") == $(materialItems[k - 1]).attr("templateId")) {
									$(materialItems[k]).find(".d1").clone().appendTo($(materialItems[k - 1]));
									$(materialItems[k]).remove();
									k = 1;
								}
							}
						}
					}
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});

	}
	return {
		init: init
	};
});